// https://soj.turingedu.cn/problem/61200/
#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
const int max_size = 5 + 100;
const int maxn = 5 + 4e4;

int n;
int a[maxn], b[maxn], h[maxn];
pair<int, int> event[maxn << 1]; // 存储事件，frist 是事件的发生时间，second 是事件类型
int esiz;

int main() {
    n = rad();
    rf(i, n) {
        a[i] = rad(), b[i] = rad(), h[i] = rad();
        event[esiz++] = {a[i], +i}; // 正数事件是插入 h[i]
        event[esiz++] = {b[i], -i}; // 负数事件是删除 h[-i]
    }
    sort(event, event + esiz);
    multiset<int> st = {0};
    ll ans = 0;
    for (int j = 0; j < esiz; ++j) {
        // puts("g");
        if (event[j].second > 0) {
            int i = event[j].second; // 进入
            st.insert(h[i]);
        } else {
            int i = -event[j].second; // 删除
            st.erase(st.find(h[i]));
        }
        ans += (ll)(event[j + 1].first - event[j].first) * (*st.rbegin());
    }
    cout << ans << endl;
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}